Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online DDL: DROP TABLE translated to RENAME TABLE statement #7221

Merged
merged 17 commits into from
Jan 5, 2021

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Dec 23, 2020

Description

Starting #7083, CREATE and DROP tables can execute as Online-DDL, meaning they're scheduled, audited and executed by tablet servers.

With this PR, a DROP TABLE statement is not only treated as online DDL, it is actually converted to a RENAME TABLE statement, to work with the table lifecycle mechanism.

The table is renamed into something like _vt_HOLD_b0d1fb34450a11ebb980f875a4d24e90_20201226103654. By just having that kind of name, the table is later garbage-collected by the lifecycle mechanism, to be purged->evacuated->dropped.

We take care of DROP TABLE IF EXISTS by checking the return code from the RENAME TABLE statement, and ignoring the specific error that indicates the table does not exist.

Also in this PR, CREATE and DROP are supported through vtgate. Previously they were only supported by vtctl.

Last, also in this PR, is retaining the GC UUID (b0d1fb34450a11ebb980f875a4d24e90 in the above _vt_HOLD_b0d1fb34450a11ebb980f875a4d24e90_20201226103654 example) such that:

  • The initial UUID is based on the Online DDL UUID. e.g.:
mysql> drop table tt;
+--------------------------------------+
| uuid                                 |
+--------------------------------------+
| b0d1fb34_450a_11eb_b980_f875a4d24e90 |
+--------------------------------------+

... time passes ...

mysql> show tables;
+----------------------------------------------------------+
| Tables_in_vt_commerce                                    |
+----------------------------------------------------------+
| _vt_HOLD_b0d1fb34450a11ebb980f875a4d24e90_20201226103654 |
| corder                                                   |
| customer                                                 |
| product                                                  |
+----------------------------------------------------------+
  • transitioning into next state, same UUID is reused, e.g. that table will transform into _vt_PURGE_b0d1fb34450a11ebb980f875a4d24e90_20201230103654
  • online ALTER TABLE artifacts are similarly named after the Online DDL UUID

There can be no conflict of naming because both state (HOLD, PURGE, etc.) as well as timestamps differ, even when using same UUID.

Related Issue(s)

tracking: #6689, #6926
Related: #7083
Depends on: #7151

Checklist

  • Should this PR be backported?
  • Tests were added or are not required
  • Documentation was added or is not required

Impacted Areas in Vitess

Components that this PR will affect:

  • Query Serving
  • VReplication
  • Cluster Management
  • Build

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
artifact tables are named after the migration UUID (this helps in tracking their origin)

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach changed the title Online ddl drop to rename Online DDL: DROP TABLE translated to RENAME TABLE statement Dec 23, 2020
@shlomi-noach shlomi-noach marked this pull request as ready for review December 23, 2020 11:22
@shlomi-noach
Copy link
Contributor Author

Depends on: #7151

… DDL, otherwise consider them as direct regardless of ddl_strategy

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

Documentation PR to follow.

…o-rename

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

Request for review

@rohit-nayak-ps rohit-nayak-ps self-requested a review January 4, 2021 16:41
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

go/vt/vttablet/onlineddl/executor.go Outdated Show resolved Hide resolved
go/vt/schema/online_ddl_test.go Outdated Show resolved Hide resolved
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

Merge conflicts are due to #7235
See proposed solution in #7247

stmt, err := sqlparser.Parse(sql)
if err != nil {
return action, ddlStmt, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, err)
return ddlStmt, action, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, err)
Copy link
Collaborator

@systay systay Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:nit: :rant: This is confusing code. I know the old code did this, but we should fix it while we are in here. ddlStmt and action have not been assigned to here, so this is equivalent to

return nil, nil, fmt.Errorf("Error parsing statement: SQL=%s, error=%+v", sql, err)

I would suggest to not use named return arguments unless they help readability or need to be changed by a defer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally find this to be more idiomatic, because I don't need to think about the actual datatype for those return variables and I don't need to think about what's the default return value -- it's implicitly done on my behalf. Also, to me, it more readable to see what's being returned semantically.

Having said that I don't feel strongly and I'll adapt per your review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right to point out that confusing is highly subjective.

Let me explain where I'm coming from. I've always felt that it's important to return empty or nil values from a function when an error occurs. Some functions allow you to return both a valid value and an error (example: https://golang.org/src/io/io.go?s=11741:11795#L322), so I always make sure to explicitly return nil or empty values when the function doesn't have a valid value to return.

The named return argument pattern makes it a little more difficult for a casual reader to see if we are returning the result as far as we got when the error occurred, or an empty value to signal that nothing was actually done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I see it, when an error is returned, in vast majority of cases the other values do not matter (are expected to be ignored). Therefore, it is only a rare occasion where those values will be checked. To me the code is more readable where I understand what it is that I'm returning semantically (e.g. this is the uuid rather than ""). And it's only the rare occasions where I need to worry about the actual values returned.

So I guess my confusion is the inversion of yours...

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

fixing failed tests after merging conflicts

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

endtoend tests fixed

@shlomi-noach
Copy link
Contributor Author

to be followed by a documentation PR

@shlomi-noach shlomi-noach merged commit 30b462a into vitessio:master Jan 5, 2021
@shlomi-noach shlomi-noach deleted the online-ddl-drop-to-rename branch January 5, 2021 13:37
@askdba askdba added this to the v9.0 milestone Jan 6, 2021
@shlomi-noach
Copy link
Contributor Author

documentation added and merged in vitessio/website#663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants